package ${cfg.basePackage}.db.gen.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ${cfg.basePackage}.db.gen.entity.Ad;
import ${cfg.basePackage}.db.util.DaoConst;
import ${cfg.basePackage}.db.util.DaoKit;
import ${cfg.basePackage}.db.util.Wrapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * ${table.comment!}Dao接口
 * </p>
 *
 * @author TODO
 * @date ${date}
 */
@Mapper
@Component
<#if kotlin>
interface ${table.mapperName} : ${superMapperClass}<${entity}>
<#else>
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {

    /**
     * 是否存在
     */
    default boolean isHave(Object tableId) {
        return selectById(tableId.toString()) != null;
    }

    /**
     * 是否存在
     */
    default boolean isHave(Wrapper<${entity}> wrapper) {
        return selectList(wrapper).size() > 0;
    }

    /**
     * 是否存在 (自动排除空参数（null,空字符串 都视作空）)
     *
     * @param entityParam 实体类参数
     */
    default boolean isHave(${entity} entityParam) {
        Wrapper<${entity}> ${table.entityPath}Wrapper = new Wrapper<>();
        DaoKit.setParam(${table.entityPath}Wrapper, entityParam, DaoConst.eq);
        return selectList(${table.entityPath}Wrapper).size() > 0;
    }

    /**
     * 返回指定条数
     */
    default List<${entity}> selectList(Wrapper<${entity}> wrapper, Object limit) {
        wrapper.apply(" limit " + limit);
        return selectList(wrapper);
    }

    /**
     * 返回指定条数
     * 从  offset 条开始
     * 返回 limit 条数据
     */
    default List<${entity}> selectList(Wrapper<${entity}> wrapper, Object limit, Object offset) {
        wrapper.apply(" limit " + limit + " offset " + offset);
        return selectList(wrapper);
    }

    //参考用法 -- 关联表分页查询参考
    //    @Select("select 0_${table.entityPath}.*,a_user.name as userName, a_user.phone as userPhone "
    //            + "from 0_${table.entityPath} "
    //            + "left join a_user on 0_${table.entityPath}.create_uid=a_user.id "
    //            + "ew.customSqlSegment")
    //    IPage<${entity}> leftJoinPage(Page<${entity}> page, @Param(Constants.WRAPPER) Wrapper<${entity}> wrapper);

}
</#if>
